import itertools

players = ['m', 'e', 'r', 'f']
players_map = {
    'm': 'Mike',
    'e': 'Ellie',
    'r': 'Rohan',
    'f': 'Fatma'
}
bike_color = ['red', 'blue', 'green', 'purple']

def run_game():
    tep_list = []
    result = []
    visited = [[0] * 4 for _ in range(4)]
    #组合出4 * 4 * 4 条数据
    for idx, pl in enumerate(players):
        for jdx, color in enumerate(bike_color):
            if (visited[idx][jdx] == 0):
                visited[idx][jdx] = 1
                for _rank in range(len(players)):
                    tep_list.append((pl, color, _rank))
    #从64 条中选4条 的组合情况
    for tup in itertools.combinations(tep_list, 4):
        _name_visited = set()
        _color_visited = set()
        _rank_visited = set()
        _tmp_list = [0] * 4
        for t in tup:
            _name = t[0]
            _color = t[1]
            _rank = t[2]
            if (_judgeName(_name, _color, _rank)):
                break;
            _name_visited.add(_name)
            _color_visited.add(_color)
            _rank_visited.add(_rank)
            _tmp_list[_rank] = (_name, _color)

        if (len(_name_visited) == 4 and len(_color_visited) == 4 and len(_rank_visited) == 4):
            if _judge_rank(_tmp_list):
                result.append(_tmp_list)
    return result

#判断前两条线索
def _judgeName(name, color, rank):
    if name == 'e':
        if color == 'purple':
            if (rank == 0 or rank == 3 ):
                return True
            else:
                return False
        else:
            return True
    if name == 'r':
        if color != 'green':
            return False
        return True
    if name == 'm':
        if (rank == 0 or rank == 3):
            return True
        return False
    if name == 'f':
        if color == 'blue':
            return True
    return False

#判断后两条线索
def _judge_rank(_list):
    _index_blue, _index_F, _index_green, _index_purple = 0, 0, 0, 0
    for _idx, _tup in enumerate(_list):
        if _tup[0] == 'f':
            _index_F = _idx
        if _tup[1] == 'blue':
            _index_blue = _idx
        if _tup[1] == 'green':
            _index_green = _idx
        if _tup[1] == 'purple':
            _index_purple = _idx
    if (_index_blue < _index_F) and (_index_green < _index_purple) :
        return True
    return False

if __name__ == '__main__':
    lis = run_game()
    for _lis in lis:
        for idx, item in enumerate(_lis):
            if idx == 1:
                print(players_map[item[0]])